package cn.openea.perpartner.payment.web.order.controller;


import cn.openea.perpartner.common.core.web.controller.BaseController;
import cn.openea.perpartner.common.core.web.domain.AjaxResult;
import cn.openea.perpartner.common.core.web.page.TableDataInfo;
import cn.openea.perpartner.payment.web.order.entity.Order;
import cn.openea.perpartner.payment.web.order.entity.dto.SearchDto;
import cn.openea.perpartner.payment.web.order.service.IOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Order)表控制层
 *
 * @author Weird077
 * @since 2023-01-28 11:59:41
 */
@Api(tags = "订单管理")
@RestController
@RequestMapping("/order")
public class OrderController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private IOrderService orderService;


    @ApiOperation("分页查询")
    @PostMapping("/list")
    public TableDataInfo selectOrderList(@RequestBody SearchDto dto) {
        startPage();
        List<Order> list = this.orderService.selectList(dto);
        return getDataTable(list);
    }

    @ApiOperation("查询订单")
    @PostMapping("/getById")
    public AjaxResult selectOrderDetail(@RequestBody Order order) {
        return success(this.orderService.getById(order.getOrderId()));
    }

    @ApiOperation("新增订单")
    @PostMapping("/add")
    public AjaxResult addOrder(@RequestBody Order order) {

        return toAjax(this.orderService.save(order));
    }

    @ApiOperation("修改订单")
    @PostMapping("/edit")
    public AjaxResult editOrder(@RequestBody Order order) {

        return toAjax(this.orderService.updateById(order));
    }
    @ApiOperation("删除订单")
    @PostMapping("/delete")
    public AjaxResult deleteOrder(@RequestBody List<Long> idList) {
        return toAjax(this.orderService.removeBatchByIds(idList));
    }
}

